package com.getword;

public class Demo2
{
    // 论证：线程终端
    public static void main(String[] args)
        throws InterruptedException
    {
        Thread th1 = new Thread(() ->
        {
            int sum = 0;
            System.out.println("th1 start..");
            long start = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++)
            {
                if (sum % 2 == 0)
                {
                    sum+=2;
                }
            }
            System.out.println("sum:" + sum + "  time:" + (System.currentTimeMillis() - start));
            try
            {
                Thread.currentThread().sleep(1000);
            }
            catch (InterruptedException e)
            {
                e.printStackTrace();
            }

        });
        th1.start();
        Thread.currentThread().sleep(3);
        System.out.println("main1");
        th1.interrupt();
        System.out.println("interrupt..");


    }
}
